#!/bin/env python

class Elem:
    def value(self): pass
    def write(self, to, s): pass
    def gen(self, to): self.write(to, self.value)
    def __str__(self): return str(self.value())
    def __int__(self): return int(str(self.value()))
    def __float__(self): return float(str(self.value()))

class Str(Elem):
    def __init__(self, value): self.string = value
    def value(self): return self.string
    def append(self, element): return Seq(self, element)

class Empty(Str):
    def __init__(self): Str.__init__(self, "")
    def append(self, element): return element

class Seq(Elem):
    def __init__(self, *rules): self.seq = list(rules)
    def append(self, rule):
        self.seq.insert(0, rule)
        return self

class Args(Elem):
    def __init__(self, item):
        self.items = [item]
    def append(self, item):
        self.items.append(item)
        return self
    def __getitem__(self, i): return self.items[i]

class Item(Elem):
    def __init__(self, rules, rate = Str("1")):
        self.rules = rules
        self.rate  = rate
    def value(self): return self.rules.value()

